package com.imooc.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.imooc.mapper.CarouselMapper;
import com.imooc.pojo.Carousel;
import com.imooc.service.CarouselService;
import java.util.List;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
@AllArgsConstructor
public class CarouselServiceImpl implements CarouselService {

  private final CarouselMapper carouselMapper;

  @Transactional(rollbackFor = Exception.class, propagation = Propagation.SUPPORTS)
  @Override
  public List<Carousel> queryAll(Integer isShow) {
    return carouselMapper
        .selectList(Wrappers.<Carousel>lambdaQuery()
            .eq(Carousel::getIsShow, isShow)
            .orderByDesc(Carousel::getSort));
  }
}